<template>
	<view class="news">
		<news-item @itemClick="goDetail" :list="newsList"></news-item>
	</view>
</template>

<script>
	import newsItem from "../../components/news-item/news-item.vue"
	export default {
		data() {
			return {
				newsList:[]
			}
		},
		methods: {
			async getNews(){
				const res = await this.$myRequest({
					url:'/api/shop/getnewslist'
				})
				console.log(res)
				this.newsList = res.data.message
			},
			//父组件定义goDetail方法跳转到news-detail页面
			goDetail (id) {
							console.log(id)
							uni.navigateTo({
								url: '/pages/news-detail/news-detail?id='+id
							})
						}
			
		},
		components: {"news-item":newsItem},
		onLoad(){
			this.getNews()
		}
	}
</script>

<style lang="scss">
	
</style>
